#include<bits/stdc++.h>
using namespace std;
#define int long long
#define pii pair<int,int>
#define pb push_back
const int N=1e6+5;

int n,SA[N],id[N],d[N*2];

struct solver{
	vector<pii> e[N];
	void add(int x,int y,int w){// y-x>=w
		// cerr<<x<<" -> "<<y<<' '<<w<<endl;
		e[x].pb({y,-w});
	}
	int dis[N],cnt[N];bool vis[N];
	bool solve(int s){
		for(int i=1;i<=n;i++) dis[i]=vis[i]=cnt[i]=0;
		queue<int> q;
		q.push(s);vis[s]=1;dis[s]=-1;
		while(!q.empty()){
			int x=q.front();q.pop(),vis[x]=0;
			for(auto p:e[x]){
				int y=p.first,v=p.second;
				if(dis[y]>dis[x]+v){
					cnt[y]++;if(cnt[y]>=n+1) return 0;
					dis[y]=dis[x]+v;
					if(!vis[y]) vis[y]=1,q.push(y);
				}
			}
		}
		return 1;
	}
	void init(){
		for(int i=1;i<=n;i++) e[i].clear();
	}
}slv;

int fa[N];int find(int x){return x==fa[x]?x:fa[x]=find(fa[x]);}
void merge(int x,int y){// x->y
	fa[find(x)]=find(y);
}
void add0(int x,int y){
	if(id[x]>id[y]) swap(x,y);
	x=id[x],y=id[y];
	merge(y,x);
}
void work1(){
	int mn=1e9;
	for(int i=n;i>1;i--){
		mn=min(mn,find(i));
		slv.add(SA[i-1],SA[i],0);
		if(mn<i) slv.add(SA[i],SA[i-1],0);
	}
}

void add1(int x,int y){
	if(x<1||x>n||y<1||y>n) return;
	// cerr<<x<<' '<<y<<' '<<id[x]<<' '<<id[y]<<endl;
	if(id[x]<id[y]) slv.add(x,y,1);
	else slv.add(y,x,1);
}

void work(){
	int i,j;
	cin>>n;
	slv.init();
	for(i=1;i<=n;i++) fa[i]=i;
	
	for(i=1;i<=n;i++) cin>>SA[i],SA[i]++,id[SA[i]]=i;
	SA[0]=n+1;id[n+1]=0;
	
	for(i=1;i<=2*n-1;i++) cin>>d[i];
	
	for(i=1;i<=2*n-1;i+=2){
		for(j=1;j<=d[i]/2;j++) add0(i/2+1-j,i/2+1+j);
		add1(i/2+1-d[i]/2-1,i/2+1+d[i]/2+1);
	}
	// cerr<<endl;
	for(i=2;i<=2*n-1;i+=2){
		for(j=1;j<=d[i]/2;j++) add0(i/2-j+1,i/2+j);
		add1(i/2-d[i]/2,i/2+1+d[i]/2);
	}
	work1();
	
	for(i=2;i<=n;i++){
		for(j=1;j+i-1<=n;j++){
			int k=j+i-1;
			if((id[j]<id[k])^(id[j+1]<id[k+1])){
				add1(j,k);
			}
		}
	}
	
	if(!slv.solve(SA[1])){cout<<"-1\n";return;}
	if(-slv.dis[SA[n]]>26){cout<<"-1\n";return;}
	for(i=1;i<=n;i++) cout<<char('a'-1-slv.dis[i]);cout<<'\n';
}
signed main(){
	freopen("string.in","r",stdin);
	freopen("string.out","w",stdout);
	cin.tie(nullptr)->sync_with_stdio(false);
	int _;cin>>_;while(_--) work();
	return 0;
}